package com.timemaneger.thinkintime;

import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;

import com.timemaneger.thinkintime.richeditor.RichEditor;

public class PreviewActivity extends AppCompatActivity {
    private InputMethodManager imm;//软键盘管理器
    private RichEditor pre_editor;
    private String html;
    private String title;
    private EditText title_txt;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_preview);
        pre_editor = (RichEditor) findViewById(R.id.pre_editor);
        pre_editor.setEditorFontSize(15);
        pre_editor.setPadding(10, 10, 10, 50);
        Intent intent=getIntent();
        html=intent.getStringExtra("html");
        String background=intent.getStringExtra("bg");
        int i=0;
        if(background.equals("desert")){
            i=R.mipmap.desert;
        }else if(background.equals("bamboo")){
            i=R.mipmap.bamboo;
        }else if(background.equals("lemon")){
            i=R.mipmap.lemon;
        }else if(background.equals("leaf")){
            i=R.mipmap.leaf;
        }else if(background.equals("block")){
            i=R.mipmap.block;
        }
        pre_editor.setBackgroundResource(i);
        pre_editor.setHtml(html);
        title=intent.getStringExtra("title");
        title_txt=(EditText) findViewById(R.id.pre_title);
        title_txt.setText(title);
        imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        pre_editor.requestFocusFromTouch();
        imm.hideSoftInputFromWindow(pre_editor.getWindowToken(), 0); //强制隐藏键盘
    }
}
